
package com.javabase.y2022.m04.day0509.v1;

import java.util.ArrayList;
import java.util.List;

/**
 * @descriptions: Solution
 * @author: Tom
 * @date: 2022/5/9 下午 02:38
 * @version: 1.0
 */
public class Solution {
    public static void main(String[] args) {
        String s = "III";
        int[] ans = new Solution().diStringMatch(s);
        for (int i = 0; i < ans.length; i++) {
            System.out.print(" " + ans[i]);
        }
    }
    public int[] diStringMatch(String s) {
        int n = s.length();
        int[] ans = new int[n+1];
        int high = n, low = 0;
        for (int i = 0; i < s.length(); i++) {
            // 如果perm[i] < perm[i + 1]，那么s[i] == 'I'
            //如果perm[i] > perm[i + 1]，那么 s[i] == 'D'
            if(s.charAt(i) == 'I'){
                ans[i] = low;
                low++;
            } else if(s.charAt(i) == 'D'){
                ans[i] = high;
                high--;
            }
        }
        ans[n] = low;
        return ans;
    }

}
